/*
 * Created on Feb 27, 2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.vectrics.skill.struts;

import org.apache.log4j.Logger;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.skill.Skill;
import org.vectrics.skill.SkillException;
import org.vectrics.skill.SkillRatingSet;
import org.vectrics.skill.UserEvaluation;
import org.vectrics.user.Person;
import org.vectrics.user.UserSkillRatingSet;


public class UserSkillSectionsTag extends ShowSkillSectionsTagAbstract {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4890516772836976355L;
	private transient static Logger log = Logger.getLogger(UserSkillSummaryTag.class);
	private String evaluationId = null;

	protected String getSectionEditLinkHtml(Skill skill) {
		String buttonHtml = "<a href=\"/hrs-intranet/admin/user/skill/skillEntry.do?evaluationId=" + getEvaluationId()
				+ "&userId=" + getUserId() + "&skillSection=" + skill.getCode() + "\" class=\"stdLink\">Change</a>";
		
/*			
			"<form action=\"/hrs-intranet/admin/user/skill/skillEntry.do\" method=\"POST\">";
		buttonHtml += "<input type=\"hidden\" name=\"evaluationId\" value=\"" + getEvaluationId() + "\">";
		buttonHtml += "<input type=\"hidden\" name=\"userId\" value=\"" + getUserId()  + "\">";
		buttonHtml += "<input type=\"hidden\" name=\"skillSection\" value=\"" + skill.getSkillCode() + "\">";
		buttonHtml += "<input type=\"submit\" name=\"submit\" value=\"Change\" class=\"formButton\">";
		buttonHtml += "</form>";
		*/
		return(buttonHtml);
	}

	private Long getUserId() {
		Long userId = new Long(this.getId());
		
		try {
			UserEvaluation eval = RecruitServiceLocator.getSkillProvider().findEvaluationById(new Long(this.evaluationId));
			
			userId = eval.getPerson().getId();
		}
		catch (Exception de) {
			log.error("Exception finding eval: " + this.evaluationId);
		}
		return(userId);
	}
	
	protected SkillRatingSet getSkillRatingSet() throws SkillException {
		SkillRatingSet set = null;
		if (evaluationId == null) {
			log.debug("'evaluationId' was not set before rendering");
		}
		Person person = CoreServiceLocator.getPersonService().findPersonById(this.getUserId());
		if (evaluationId == null) {
			set = new UserSkillRatingSet(person);
		}
		else {
			UserEvaluation evaluation = RecruitServiceLocator.getSkillProvider().findEvaluationById(new Long(evaluationId));
			set = RecruitServiceLocator.getSkillProvider().findUserSkillSet(evaluation);
		}
		return(set);
	}
	
	
	protected boolean getShowSkillDetails() {
		return(true);
	}
	
	/**
	 * @return Returns the evalId.
	 */
	public String getEvaluationId() {
		return evaluationId;
	}

	/**
	 * @param evalId The evalId to set.
	 */
	public void setEvaluationId(String evalId) {
		this.evaluationId = evalId;
	}

	
}
